//
//  FFBaseViewController.m
//  beichoo_N_ios
//
//  Created by 陈健 on 2017/8/21.
//  Copyright © 2017年 陈健. All rights reserved.
//

#import "FFBaseViewController.h"
#import "UIColor+Expand.h"
#import "NSString+Common.h"
#import "FFGlobalHeader.h"
#import "UIImage+Common.h"
#import <Masonry/Masonry.h>


@interface FFBaseViewController ()

@end

@implementation FFBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F6F6F8"];
    [self addNavigationRetunItem];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 添加返回按钮

- (void)addNavigationRetunItem {
    
    if ([self.navigationController.viewControllers count] == 1) {
        return;
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"left_common_arrow"] style:(UIBarButtonItemStylePlain) target:self action:@selector(returnClick)];
}

- (void)returnClick {
    if ([self.navigationController.viewControllers count] > 1) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

#pragma mark - 快捷nav右边按钮(自己添加事件)
- (void)addRightNavigationButtonWithImge:(NSString *)imageName {
    
    UIButton *rightNavigationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightNavigationButton setImage:[UIImage imageNamed:imageName]
                           forState:UIControlStateNormal];
    rightNavigationButton.frame = CGRectMake(0, 0, 16, 16);
    _rightNavigationButton = rightNavigationButton;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightNavigationButton];
    
}

- (void)addRightNavigationButtonWithTitle:(NSString *)title {
    CGSize size = [title getSizeWithFont:15
                       constrainedToSize:CGSizeMake(MAXFLOAT, 44)];
    size.width = (size.width>44)?size.width+10:44;
    UIButton *rightNavigationButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, size.width, 44)];
    [rightNavigationButton setTitle:title forState:UIControlStateNormal];
    [rightNavigationButton setTitleColor:[UIColor colorWithHexString:@"#333333"]
                                forState:UIControlStateNormal];
    rightNavigationButton.titleLabel.font = [UIFont systemFontOfSize:15];
    _rightNavigationButton = rightNavigationButton;
    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:_rightNavigationButton];
    self.navigationItem.rightBarButtonItem = rightitem;
}

@end
